<?php if(!defined('IN_INSTALL')) exit("Request Error!"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>配置数据文件</title>
<link href="templets/style/install.css" type="text/css" rel="stylesheet" />
<script type="text/javascript">
function CheckForm()
{
	CheckPwd();
	var format = /^[a-zA-Z0-9_@!.-]+$/;

	if(document.getElementById("dbinfo[dbhost]").value == "")
	{
		alert("请输入数据库服务器！");
		document.getElementById("dbinfo[dbhost]").focus();
		return false;
	}
	if(document.getElementById("dbinfo[dbname]").value == "")
	{
		alert("请输入数据库名！");
		document.getElementById("dbinfo[dbname]").focus();
		return false;
	}
	if(!format.exec(document.getElementById("dbinfo[dbname]").value))
	{
		alert("数据库名非法！请使用[a-zA-Z0-9_@!.-]内的字符！！");
		document.getElementById("dbinfo[dbname]").focus();
		return false;
	}
	if(document.getElementById("dbinfo[dbuser]").value == "")
	{
        alert ("请输入数据库用户！");
       	document.getElementById("dbinfo[dbuser]").focus();
        return false;
    }
	if(document.getElementById("cpw").value != "true")
	{
        return false;
	}
	if(document.getElementById("admininfo[username]").value == "")
	{
		alert("请输入管理员账号！");
		document.getElementById("admininfo[username]").focus();
		return false;
	}
	if(document.getElementById("admininfo[username]").value.length<5 || document.getElementById("admininfo[username]").value.length>20)
	{
		alert("用户名长度不得小于5位或大于20位！");
		document.getElementById("admininfo[username]").focus();
		return false;
	}
	if(document.getElementById("admininfo[password]").value == "")
	{
		alert("请输入管理员密码！");
		document.getElementById("admininfo[password]").focus();
		return false;
	}
	if(document.getElementById("admininfo[password]").value.length<5 || document.getElementById("admininfo[password]").value.length>16)
	{
		alert("密码由5-16个字符组成，区分大小写！");
		document.getElementById("admininfo[password]").focus();
		return false;
	}
	
	if(document.getElementById("admininfo[password2]").value == "")
	{
        alert("请输入重复密码！");
       	document.getElementById("admininfo[password2]").focus();
        return false;
    }
	if(document.getElementById("admininfo[password]").value != document.getElementById("admininfo[password2]").value)
	{
        alert("两次密码不同！");
        document.getElementById("admininfo[password2]").focus();
        return false;
    }

	//验证没有问题，提交表单
	document.form.submit();
}

var xmlHttp;

function xmlhttprequest()
{
	if(window.ActiveXObject)
	{
		xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
	}
	else if(window.XMLHttpRequest)
	{
		xmlHttp = new XMLHttpRequest();
	}
	else
	{
		alert('您的浏览器不支持Ajax技术！');
	}
}

function CheckPwd()
{
	xmlhttprequest();
	
	dbhost = document.getElementById("dbinfo[dbhost]").value;
	dbuser = document.getElementById("dbinfo[dbuser]").value;
	dbpw   = document.getElementById("dbinfo[dbpw]").value;

	var url = 'index.php?'+parseInt(Math.random()*(15271)+1)+'&s=15271'+'&dbhost='+dbhost+'&dbuser='+dbuser+'&dbpw='+dbpw;
	xmlHttp.open("GET", url, true);
	xmlHttp.onreadystatechange = CheckPwd_done;
	xmlHttp.send(null);
}

function CheckPwd_done()
{
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
	{
		if(xmlHttp.responseText == 'true')
		{
			document.getElementById('re_dbpw').innerHTML = '<span class="install_true" style="margin-left:22px;">可用</span>';
			document.getElementById('cpw').value = 'true';
		}
		else if(xmlHttp.responseText == 'false')
		{
			document.getElementById('re_dbpw').innerHTML = '<span class="install_false" style="margin-left:22px;">不可用</span>';
			document.getElementById('cpw').value = 'false';
		}
	}
}
</script>
</head>
<body>
<div class="header">
		<div class="step_area"><img src="templets/images/set_db.png" /></div>
</div>
<div class="mainbody">
		<div class="step_sgin"><img src="templets/images/step_sgin_second.png" /></div>
		<h2 class="install_title">填写数据库信息</h2>
		<form name="form" id="form" method="post" action="index.php">
				<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
						<tr>
								<th width="25%" height="30" align="right">数据库服务器：</th>
								<td><input value="localhost" type="text" name="dbinfo[dbhost]" id="dbinfo[dbhost]" class="class_input" />
										<span class="cnote">数据库服务器地址, 一般为 localhost</span></td>
						</tr>
						<tr>
								<th height="30" align="right">数据库名称：</th>
								<td><input value="phpmywind_db" type="text" name="dbinfo[dbname]" id="dbinfo[dbname]" class="class_input" /></td>
						</tr>
						<tr>
								<th height="30" align="right">数据库用户：</th>
								<td><input value="root" type="text" name="dbinfo[dbuser]" id="dbinfo[dbuser]" class="class_input" /></td>
						</tr>
						<tr>
								<th height="30" align="right">数据库密码：</th>
								<td><input type="password" name="dbinfo[dbpw]" id="dbinfo[dbpw]" class="class_input" onblur="CheckPwd()" />
										<span id="re_dbpw"></span>
										<input type="hidden" name="cpw" id="cpw"></td>
						</tr>
						<tr>
								<th height="30" align="right">数据表前缀：</th>
								<td><input value="pmw_" type="text" name="dbinfo[tablepre]" id="dbinfo[tablepre]" class="class_input" />
										<span class="cnote">同一数据库运行多个程序时，请修改前缀</span></td>
						</tr>
				</table>
				<h2 class="install_title">填写管理员信息</h2>
				<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
						<tr>
								<th width="25%" height="30" align="right">管理员账号：</th>
								<td><input value="admin" type="text" name="admininfo[username]" id="admininfo[username]" class="class_input" /></td>
						</tr>
						<tr>
								<th height="30" align="right">管理员密码：</th>
								<td><input value="" type="password" name="admininfo[password]" id="admininfo[password]" class="class_input" />
						</td>
						</tr>
						<tr>
								<th height="30" align="right">重复密码：</th>
								<td><input value="" type="password" name="admininfo[password2]" id="admininfo[password2]" class="class_input" /></td>
						</tr>
						<tr>
								<th height="30" align="right">安装测试数据：</th>
								<td><input value="true" checked="checked" type="checkbox" name="admininfo[testdata]" style="margin-left:5px;" />
										是</td>
						</tr>
				</table>
				<div class="inst_btn_area">
						<a href="javascript:void(0);" onclick="CheckForm();return false;">下一步</a>
						&nbsp;
						<a href="javascript:void(0);" onclick="history.go(-1);return false;">返　回</a>
						<input type="hidden" name="s" id="s" value="3">
				</div>
		</form>
</div>
<div class="footer">© 2012 m16888.cn</div>
</body>
</html>